<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>登录</title>
	<link rel="stylesheet" type="text/css" href="__STATIC__/admin/layui/css/layui.css">
	<script type="text/javascript" src="__STATIC__/admin/layui/layui.js"></script>
</head>
<body style="background: #1E9FFF">
<div style="position: absolute; left:50%;top:50%;width: 500px;margin-left: -250px;margin-top: -200px;">
	<div style="background: #ffffff;padding: 20px;border-radius: 4px;box-shadow: 5px 5px 20px #444444;">
		<div class="layui-form">
			<div class="layui-form-item" style="color:gray;">
				<h2>后台管理系统</h2>
			</div>
			<hr>
			<div class="layui-form-item">
				<label class="layui-form-label">用户名</label>
				<div class="layui-input-block">
					<input type="text" id="name" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">密&nbsp;&nbsp;&nbsp;&nbsp;码</label>
				<div class="layui-input-block">
					<input type="password" id="password" class="layui-input">
				</div>
			</div>

			{if condition="$captcha_signin == true"}
			<div class="layui-form-item">
				<label class="layui-form-label">验证码</label>
				<div class="layui-input-inline">
					<input type="text" id="verifycode" class="layui-input">
				</div>
				<img src="{:captcha_src()}" id="img" onclick="reloadImg()">
			</div>
			{else /}
			{/if}
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" onclick="dologin()">登录</button>
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
    layui.use(['layer'],function () {
        $ = layui.jquery;
        layer = layui.layer;

        // 用户名控件获取焦点
        $('#name').focus();

        // 回车键也可提交
        $('input').keydown(function(e){
            if(e.keyCode == 13){
                dologin();
            }
        });
    });

    // 重新生成验证码
    function reloadImg(){
        $('#img').attr('src','{:captcha_src()}?rand='+Math.random());
    }

    // 登录
    function dologin(){
        var name = $.trim($('#name').val());
        var password = $.trim($('#password').val());
        var verifycode = $.trim($('#verifycode').val());

        $.post('/admin.php/admin/Account/dologin',{'name':name,'password':password,'verifycode':verifycode},function(res){
            if(res.code>0){
                layer.msg(res.msg);
                setTimeout(function(){window.location.href = '/admin.php/admin/Home/index'},100);
            }else{
                reloadImg(); // 重新调用生成验证码方法（目的刷新验证码）
                layer.alert(res.msg,{icon:2});
            }
        },'json');
    }
</script>

</body>
</html>